package top.yamhk.agent.utils;

import cn.hutool.json.JSONUtil;

import java.util.HashMap;

/**
 * JSON工具类
 *
 * @author 庆 HongKong
 * @date 2020/8/20 16:04
 */
public class JsonUtils {
    /**
     * json
     */
//    public static final Gson GSON = new GsonBuilder()
//            .disableHtmlEscaping()
//            .setDateFormat("yyyy-MM-dd HH:mm:ss")
//            .create();

    /**
     * 私有构造方法
     */
    private JsonUtils() {
    }

    public static String toJson(Object object) {
        return JSONUtil.toJsonStr(object);
    }

    public static <T> T fromJson(String sourceStr, Class<T> mockUtilClass) {
        return JSONUtil.toBean(sourceStr, mockUtilClass);
    }

    public static String getTargetFromJsonStr(Object jsonStr, String target) {
        return String.valueOf(JsonUtils.fromJson((String) jsonStr, HashMap.class).get(target));
    }
}